package com.silence.springboot.controller;

import com.silence.springboot.common.Result;
import com.silence.springboot.service.LoginService;
import com.silence.springboot.vo.input.LoginSystemInput;
import com.silence.springboot.vo.input.RegisterUserInput;
import com.silence.springboot.vo.input.UpdatePasswordInput;
import com.silence.springboot.vo.output.LoginSystemOutput;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 登录表 控制层。
 *
 * @author mybatis-flex-helper automatic generation
 * @since 1.0
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/login")
@Tag(name = "登录表控制层")
public class LoginController {

    /**
     * 登录表
     */
    private final LoginService loginService;

    /**
     * 注册用户
     *
     * @param input 注册用户入参
     * @return 结果
     */
    @PostMapping("/registerUser")
    @Operation(summary = "注册用户", description = "注册用户")
    public Result<Void> registerUser(@Validated @RequestBody RegisterUserInput input) {
        // 返回成功
        loginService.registerUser(input);
        return Result.success();
    }

    /**
     * 登录系统
     *
     * @param input 登录表实体类
     * @return 结果
     */
    @PostMapping("/loginSystem")
    @Operation(summary = "登录", description = "登录")
    public Result<LoginSystemOutput> loginSystem(@Validated @RequestBody LoginSystemInput input) {
        // 返回成功
        return Result.success(loginService.loginAdminSystem(input));
    }

    /**
     * 更新密码
     *
     * @param input 入参
     * @return 结果
     */
    @PostMapping("/updatePassword")
    @Operation(summary = "更新密码", description = "更新密码")
    public Result<Void> updatePassword(@Validated @RequestBody UpdatePasswordInput input) {
        // 返回成功
        loginService.updatePassword(input);
        return Result.success();
    }

}